package com.yc.ServerClient;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class Test4_Client {
    //Test3的客户端程序
    public static void main(String[] args) throws IOException {
        Socket s=new Socket("localhost",10001);
        System.out.println("联接成功！"+s);

        //用输入流来接时间
        try(InputStreamReader iis=new InputStreamReader(s.getInputStream());){
            char[] chs=new char[1024];                                     //注意客户端接收时 也要用字符流来接收 所以这里的byte[] 转为字符数组
            int length=-1;

            while ( (length=iis.read( chs,0,chs.length ))!=-1  ){
                String str=new String( chs,0,length );
                System.out.println(str);
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
        System.out.println("客户端断开与服务器的联接");
        s.close();

    }
}
